<script language = "Javascript">

// Fetch all the users
function addUserCallback (data, textStatus) {
 res_space = document.getElementById("paginlink2");
 if(data[0] == true)
	{
		uname = document.getElementById("username");
		email = document.getElementById("email");
		utype = document.getElementById("utype");
		msg="User <strong>"+uname.value+"</strong> created successfully with e-mail id <strong>"+email.value+"</strong>";
		res_space.innerHTML = msg;
	}
 else if(data[0] == false)
	{
		msg = data[1];
		res_space.innerHTML = msg;
	}
}
function getUTypes(data, textStatus) {
	utype = document.getElementById("utype");
	for(key in data)
	{
		row = data[key];
		var newopt = document.createElement('option');
		newopt.innerHTML = row["usertype_name"] ;
		newopt.setAttribute('value',row["usertype"]);
		utype.appendChild(newopt);
	}
}


$(document).ready(function(){
	fetchUType = {"getUserType":true};
	$.post(baseurl+"admin/users.mod.php", fetchUType,getUTypes, "json");
})
function addNewUser()
{
	uname = document.getElementById("username");
	email = document.getElementById("email");
	password1 = document.getElementById("passwd1");
	password2 = document.getElementById("passwd2");
	utype = document.getElementById("utype");

	addUserData = {"adduser":true, "username":uname.value,"email":email.value,"passwrd":password1.value,"passwrd2":password2.value,"type":utype.value};
	$.post(baseurl+"admin/users.mod.php", addUserData,addUserCallback, "json");
}

</script>

<div id="topic-head">Add User</div>

<div id = "paginlink"></div>
<div id = "formwrap">
<table border='0' id='wrapout'>
<tr height='20'><td id='topic-body'>Username</td><td id='topic-body'><input type='text' id='username'></td></tr>
<tr height='20'><td id='topic-body'>Email</td><td id='topic-body'><input type='text' id='email'></td></tr>
<tr height='20'><td id='topic-body'>Password</td><td id='topic-body'><input type='password' id='passwd1'></td></tr>
<tr height='20'><td id='topic-body'>Re-Type Password</td><td id='topic-body'><input type='password' id='passwd2'></td></tr>
<tr height='20'><td id='topic-body'>User Type</td><td id='topic-body'><select id='utype'></select></td></tr>
<tr height='20'><td colspan='2' align='center'><p align='center'><input type='button' value="Add User" id='searchbar' onClick="addNewUser()"></a></td></tr>
</table>
</div>
<div id="paginlink2">
</div>


